package gof.com.yew.Iterator;

import java.util.ArrayList;
import java.util.List;

//聚合对象---存储数据
public class MyContainer implements Container {
	
	private List<Object> lists = new ArrayList<>();

	public List<Object> getLists() {
		return lists;
	}

	public void setLists(List<Object> lists) {
		this.lists = lists;
	}

	public  Iterator getIterator() {
		return new MyIterator();
	}
	
	public void addObject(Object obj) {
		lists.add(obj);
	}
	
	public Object removeObject(Object obj) {
		return lists.remove(obj);
	}
	
	//静态内部类---迭代器实现类
	private class MyIterator implements Iterator{
		int cursor;
		
		@Override
		public boolean hasNext() {
			if(cursor<lists.size()) {
				return true;
			}
			return false;
		}

		@Override
		public Object next() {
			if(cursor<lists.size()) {
				return lists.get(cursor++);
			}
			return null;
		}
	}

}
